<style lang="less" scoped>

  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #20a0ff;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }

  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }

  .f-w70 {
    width: 50%;
  }

  .f-w125 {
    width: 125%;
  }

  .f-w100 {
    width: 100%;
  }

  .my {
    margin-left: -60px;
  }

  .f-w120 {
    width: 120%;
  }

  .el-table {
    flex: 1;
    .el-icon-check {
      display: none;
    }
    .current-row {
      .el-icon-check {
        display: inline-block;
      }
    }

  }

  .el-dialog {
    flex: 1;
    .isreceipt {
      display: none;
    }
    .receipt {
      display: inline-block;
    }
  }

</style>

<template>
  <section>
    <search-bar>
      <el-row>
        <el-col :span="8">
          <el-form-item label="名称">
            <el-input  style="width: 375px" v-model="coupon" placeholder="请输入优惠券名称"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="类型">
            <el-select v-model="conponTypeValue"
                       placeholder="请选择">
              <el-option
                v-for="item in conponType"
                :label="item.cnDictValname"
                :key="item.dictVal"
                :value="item.dictVal">
              </el-option>

            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="状态">
            <el-select  v-model="couponStatusValue"
                       placeholder="请选择">
              <el-option
                v-for="item in couponStatus"
                :label="item.cnDictValname"
                :key="item.dictVal"
                :value="item.dictVal">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </search-bar>

    <!-- 操作 -->
    <el-col :span="24" style="margin-bottom: 10px">
      <el-button type="primary" @click="handleAdd">新增</el-button>
      <el-button type="primary" @click="resetCondition" style="float: right">重置</el-button>
      <el-button type="primary" @click="searchCoupon" style="float: right">查询</el-button>
    </el-col>
    <!--列表-->
    <el-table :data="tableData" highlight-current-row border @sort-change="sortChange"
              @selection-change="selsChange" v-loading="listLoading" style="width: 100%;">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column prop="name" label="优惠券名称"  width="150">
      </el-table-column>
      <el-table-column prop="typeName" label="类型"  width="130">
      </el-table-column>
      <el-table-column prop="statusName" label="状态"  width="120">
      </el-table-column>
      <el-table-column prop="faceValue" label="面值/折扣" width="100">
        <template slot-scope="faceValue">
          <li v-if="faceValue.row.typeName=='抵用券'" style="list-style: none">
            {{faceValue.row.faceValue}}

          </li>
          <li v-if="faceValue.row.typeName=='折扣券'" style="list-style: none">
            {{faceValue.row.faceValue}}%

          </li>
        </template>
      </el-table-column>
      <el-table-column prop="useCondition" label="使用条件" width="120">
        <template slot-scope="condition">
          <li v-if="condition.row.useCondition==0" style="list-style: none">
            满{{condition.row.useConditionVal}}减

          </li>
          <li v-if="condition.row.useCondition==1" style="list-style: none">
            无门槛
          </li>
          <li v-if="condition.row.useCondition==2" style="list-style: none">
            只抵扣保费
          </li>
        </template>
      </el-table-column>
      <el-table-column prop="agingType" label="时效">
        <template slot-scope="aging">
          <li v-if="aging.row.agingType==0" style="list-style: none">
            {{aging.row.effectiveBeginDate.toString().substring(0, 10)}}到{{aging.row.effectiveEndDate.toString().substring(0, 10)}}

          </li>
          <li v-if="aging.row.agingType==1" style="list-style: none">
            领取后 :{{aging.row.days}} 天内使用

          </li>
        </template>
      </el-table-column>
      <el-table-column prop="grantType" label="发放方式" width="120">
        <template slot-scope="scope">

          <li v-if="scope.row.grantType==0" style="list-style: none">
            用户领取
          </li>
          <li v-if="scope.row.grantType==1" style="list-style: none">
            直接赠送
          </li>
        </template>
      </el-table-column>
      <el-table-column prop="userlevel" label="适用范围" width="120">
        <template slot-scope="useRange">
          <li v-if="useRange.row.rangeType==0" style="list-style: none">
            用户等级

          </li>
          <li v-if="useRange.row.rangeType==1" style="list-style: none">
            注册时间

          </li>
          <li v-if="useRange.row.rangeType==2" style="list-style: none">
            活跃度

          </li>
        </template>
      </el-table-column>
      <el-table-column prop="num" label="领取数/发布数" width="90">
        <template slot-scope="issueNum">
          <li v-if="issueNum.row.grantType ==0" style="list-style: none">
            {{ issueNum.row.countAmount}}/{{issueNum.row.num}}

          </li>
          <li v-if="issueNum.row.grantType ==1" style="list-style: none">
            {{ issueNum.row.countAmount}}/{{issueNum.row.countAmount}}

          </li>
        </template>
      </el-table-column>
      <el-table-column prop="useNum" label="使用数目" width="120">
      </el-table-column>
      <el-table-column label="操作" width="300" fixed="right">
        <template slot-scope="scope">
          <el-button  type="primary" v-if="scope.row.status==114003001"
                     @click="publish(scope.$index, scope.row)">发布
          </el-button>
          <el-button type="danger" v-if="scope.row.status==114003002"
                     @click="overlish(scope.$index, scope.row)">结束
          </el-button>
          <el-button  type="primary" v-if="scope.row.status==114003001"
                     @click="handleAddEit(scope.$index, scope.row);">编辑
          </el-button>
          <el-button type="primary" v-if="scope.row.status!=114003001"
                     @click="detailsView(scope.$index, scope.row)">查看详情
          </el-button>
          <el-button type="primary"  v-if="scope.row.status!=114003001"
                     @click="receiveRecord(scope.$index, scope.row)">领用记录
          </el-button>
          <el-button type="danger" v-if="scope.row.status==114003001"
                     @click="handleDel(scope.$index, scope.row)">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-pagination
        :current-page="currentPage"
        :page-size="pageSize"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total,sizes,prev, pager, next, jumper"
        :total="total" style="float: right">
      </el-pagination>
    </el-col>
    <!--领用记录弹窗-->
    <el-dialog title="领用记录" size="large" :visible.sync="myFormReceive" :close-on-click-modal="false">
      <section>
        <search-bar>
          <el-row>
            <el-col :span="12">
              <el-form-item label="使用状态">
                <el-select
                           v-model="couponReceiveStatusValue"
                           placeholder="请选择">
                  <el-option
                    v-for="item in $store.getters.COUPON_USAGE"
                    :key="item.dictVal"
                    :label="item.cnDictValname"
                    :value="item.dictVal">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="领取时间">
                <el-date-picker
                  class="f-w100"
                  v-model="ReceivePicker"
                  type="daterange"
                  align="right"
                  placeholder="选择日期范围"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </search-bar>

        <!-- 操作 -->
        <el-col :span="24" style="margin-bottom: 10px">
          <!--<el-button type="primary" @click="deriveList">导出</el-button>-->
          <el-button type="primary" @click="receiveResert" style="float: right;margin-left: 5px">重置</el-button>
          <el-button type="primary" @click="searchReceive" style="float: right">查询</el-button>
        </el-col>
        <!--列表-->
        <el-table :data="receiveTable.tableData" highlight-current-row border @sort-change="sortChange1"
                  @selection-change="selsChange1"
                  v-loading="receiveTable.listLoading" style="width: 100%;">
          <el-table-column type="selection" width="55">
          </el-table-column>
          <el-table-column type="index" width="100" label="序号">
          </el-table-column>
          <el-table-column prop="phone" label="领取账号"  width="180">
          </el-table-column>
          <el-table-column prop="createDate" label="领取时间"  width="280">
          </el-table-column>
          <el-table-column prop="statusname" label="使用状态"  width="150">
          </el-table-column>
          <el-table-column prop="useTime" label="使用时间" width="200">
          </el-table-column>
          <el-table-column prop="orderNumber" label="订单编号">
          </el-table-column>
          <el-table-column prop="orderAmount" label="订单金额（元）" width="220">
          </el-table-column>
          <el-table-column prop="discountAmount" label="优惠后订单金额（元）" width="220">
          </el-table-column>
        </el-table>
        <!--工具条-->
        <el-row>
          <el-col :span="24" class="toolbar">
            <el-pagination
              @size-change="handleSizeChange1"
              @current-change="handleCurrentChange1"
              :current-page="receiveTable.currentPage"
              :page-size="receiveTable.pageSize"
              layout="total,sizes,prev, pager, next, jumper"
              :total="receiveTable.total" style="float: right">
            </el-pagination>
          </el-col>
        </el-row>
        <!-- 弹窗 -->

      </section>
    </el-dialog>
    <!-- 新增弹窗 -->
    <el-dialog :title="dialogTitle" size="tiny" :visible.sync="myFormVisible" :close-on-click-modal="false">
      <el-form :model="myForm" label-width="120px" ref="myForm">
        <el-form-item label="优惠券类型" prop="type"
                      :rules="[{type: 'number', required: true, message: '请选择优惠券类型 ', trigger: 'change'}]">
          <el-select  v-model="myForm.type"
                     @change="myChange" placeholder="请选择">
            <el-option
              v-for="item in $store.getters.COUPON_TYPE"
              :key="item.dictVal"
              :label="item.cnDictValname"
              :value="item.dictVal">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="优惠券名称" prop="name"
          :rules="[{required: true, message: '请输入优惠券名称', trigger: 'blur'},
            {min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur'}]">
          <el-input v-model="myForm.name"   auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item v-if="myStatus==true" label="优惠券面值" prop="faceValue"
        :rules="[{type: 'number', required: true, message: '请输入数值', trigger: 'blur'}]">
          <el-input v-model.number="myForm.faceValue" ></el-input>
        </el-form-item>
        <el-form-item v-if="myStatus==false" label="优惠券折扣" prop="faceValue"
        :rules="[{type: 'number', required: true, message: '请输入数值', trigger: 'blur'}]">
          <el-input v-model.number="myForm.faceValue"  placeholder="请输入百分比">
            <template slot="append">%</template>
          </el-input>
        </el-form-item>

        <el-form-item label="发放方式" prop="grantType"
                      :rules="[{type: 'number', required: true, message: '请选择发放方式 ', trigger: 'change'}]"
                      style="margin-top: 30px">
          <el-radio-group v-model="myForm.grantType">
            <el-radio class="radio" :label="0">用户领取</el-radio>
            <el-radio class="radio" :label="1">直接赠送</el-radio>
          </el-radio-group>
        </el-form-item>

        <div v-if="myForm.grantType === 0">
          <el-form-item label="发放数量" prop="num"
          :rules="[{type: 'number', required: true, message: '请输入发放数量 ', trigger: 'blur'}]">
            <el-input v-model.number="myForm.num"  ></el-input>
          </el-form-item>
          <el-form-item label="领取次数"
                        :rules="[{type: 'number', required: true, message: '请选择领取次数', trigger: 'change'}]"
                        prop="frequency">
            <el-radio-group v-model="myForm.frequency">
              <el-radio class="radio" :label="0" >限次数
              </el-radio>
              <el-radio class="radio" :label="1" >无限制
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item v-if="myForm.frequency === 0"
                        :rules="[{type: 'number', required: true, message: '请输入限制人/次', trigger: 'change'}]"
                        prop="frequencyVal">
            <el-input  type="number" v-model.number="myForm.frequencyVal">
              <template slot="prepend">限</template>
              <template slot="append">次/人</template>
            </el-input>
          </el-form-item>
        </div>
        <div v-else-if="myForm.grantType === 1">
          <el-form-item label="赠送数量"
                        :rules="[{type: 'number', required: true, message: '请输入限制张/人', trigger: 'change'}]"
                        prop="giftQuantity">
            <el-input v-model.number="myForm.giftQuantity">
              <template slot="append">张/人</template>
            </el-input>
          </el-form-item>
          <el-form-item label="赠送时点" prop="giftPoint">
            <el-radio-group v-model="myForm.giftPoint">
              <el-radio class="radio" :label="0" >注册成功
              </el-radio>
              <el-radio class="radio" :label="1" >常规下单成功
              </el-radio>
              <el-radio class="radio" :label="2" >投保下单成功
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </div>
        <el-form-item label="使用条件"
                      :rules="[{type: 'number', required: true, message: '请选择使用条件', trigger: 'change'}]"
                      prop="useCondition">
          <el-radio-group v-model="myForm.useCondition">
            <el-radio class="radio" :label="0"  >减免</el-radio>
            <el-radio class="radio" :label="1" >无门槛</el-radio>
            <el-radio class="radio" :label="2" >只抵扣保费</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="myForm.useCondition === 0"
                      :rules="[{type: 'number', required: true, message: '请输入满多少可减免', trigger: 'change'}]"
                      prop="useConditionVal">
          <el-input type="number" v-model.number="myForm.useConditionVal">
            <template slot="prepend">满</template>
            <template slot="append">可减免</template>
          </el-input>
        </el-form-item>

        <el-form-item label="优惠券时效"
                      :rules="[{type: 'number', required: true, message: '请选择优惠券时效', trigger: 'change'}]"
                      prop="agingType">
          <el-radio-group v-model="myForm.agingType">
            <el-radio class="radio" :label="0">按时间区间</el-radio>
            <el-radio class="radio" :label="1">按领取天数</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item style="margin-top: 15px" v-if="myForm.agingType == 0"
                      :rules="[{type: 'array', required: true, message: '请选择日期范围', trigger: 'change'}]"
                      prop="myCreateDate">
          <el-date-picker
            v-model="myForm.myCreateDate"
            type="daterange"
            align="right"
            placeholder="选择日期范围">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" v-if="myForm.agingType == 1"
                      :rules="[{type: 'number', required: true, message: '请输入天数', trigger: 'change'}]"
                      prop="days">
          <el-input type="number" v-model.number="myForm.days">
            <template slot="prepend">领取后</template>
            <template slot="append">天内使用</template>
          </el-input>
        </el-form-item>

        <el-form-item label="使用范围"
                      :rules="[{type: 'number', required: true, message: '请选择使用范围', trigger: 'change'}]"
                      prop="rangeType">
          <el-radio-group v-model="myForm.rangeType">
            <el-radio :label="0" style="float: left">用户等级</el-radio>
            <el-radio :label="1" style="float: left">注册时间</el-radio>
            <el-radio :label="2" style="float: left">活跃度</el-radio>
          </el-radio-group>
          <el-form-item
            :rules="[{type: 'number', required: true, message: '请选择等级', trigger: 'change'}]"
            prop="userlevel" v-if="myForm.rangeType == 0">
            <el-select v-model="myForm.userlevel"  placeholder="请选择等级">
              <el-option
                v-for="item in $store.getters.MEMBERSHIP_GRADE"
                :key="item.dictVal"
                :label="item.cnDictValname"
                :value="item.dictVal">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item v-if="myForm.rangeType == 1" label="选择日期范围"
                        :rules="[{type: 'array', required: true, message: '选择日期范围', trigger: 'change'}]"
                        prop="registerDate">
            <el-date-picker v-model="myForm.registerDate"
                            type="daterange" placeholder="选择日期范围">
            </el-date-picker>
          </el-form-item>

          <el-form-item
            :rules="[{type: 'number', required: true, message: '请选择活跃度', trigger: 'change'}]"
            prop="activityDegree" v-if="myForm.rangeType == 2">
            <el-select v-model="myForm.activityDegree"
                       placeholder="请选择活跃度">
              <el-option
                v-for="item in $store.getters.USER_ACTIVITY"
                :key="item.dictVal"
                :label="item.cnDictValname"
                :value="item.dictVal">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form-item>

        <el-form-item label="优惠券叠加"
                      :rules="[{type: 'number', required: true, message: '请选择优惠券叠加', trigger: 'change'}]"
                      prop="overlayType">
          <el-radio-group v-model="myForm.overlayType">
            <el-radio class="radio" :label="0">不可与其他优惠叠加使用</el-radio>
            <el-radio class="radio" :label="1">可与其他优惠叠加使用</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item  label="备注说明">
          <el-input type="textarea" class="f-w70"
                    spellcheck="添加使用说明(选填)"
                    :autosize="{ minRows: 5, maxRows:5 }"
                    v-model="myForm.remark">
          </el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer" style="margin-top: -10px">
        <el-button @click.native="myFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="handleSubmit(114003001)" :loading="submitLoading"
                   v-bind:class="{ active: isActive.hasFalse }">提交
        </el-button>

        <el-button type="primary" @click.native="handleSubmit(114003002)" :loading="submitLoading"
                   v-bind:class="{ active: isActive.hasFalse }">提交并发布
        </el-button>

      </div>
    </el-dialog>
  </section>
</template>

<script>
import {searchDictEntitys} from '../../api/v3/stmDict.js';
import {
  getCoupons,
  saveCoupons,
  batchCoupons,
  publishDiscount,
  getReceiveList
} from '../../api/v3/couponApi.js';
export default {
  data () {
    return {
      ReceivePicker: '',
      couponReceiveStatusValue: '',
      couponReceiveStatus: [],

      AddCouponstype: [], // 新增--类型
      AddCouponstypeValue: '', // 新增--类型

      couponStatus: [], // 搜索栏--状态
      couponStatusValue: '', // 搜索栏--状态
      conponType: [], // 搜索栏--类型
      conponTypeValue: '', // 搜索栏--类型

      myStatus: false,

      isActive: {
        isTrue: true,
        hasFalse: false
      },
      choseForm: false,
      coupon: '', // 搜索栏---名称
      dialogTitle: '新增',
      condition: {
        name: '',
        number: ''
      },
      chose_dateRange: {
        start: '',
        over: ''
      },

      uese_grad: '1',

      discount: '1',
      // 等级
      use_grade: [],
      // 优惠券类型

      chageTypeVal: '',
      // 活跃度
      liveness: [],
      livenessVal: '',
      sels: [],
      tableDataReceive: [],

      total: 0,
      currentPage: 1,
      pageSize: 10,
      sortProp: null,
      sortOrder: 'ascending',
      listLoading: false,
      listLoading1: false,
      myFormReceive: false,

      submitLoading: false,
      // 表单数据
      myForm: {
        'name': null,
        'statusName': null,
        'myCreateDate': [],
        'registerDate': [],
        'remark': null,
        'type': '',
        'isIssue': null,
        'faceValue': null,
        'useCondition': 0,
        'useConditionVal': null,
        'frequency': null,
        'frequencyVal': '',
        'agingType': 0,
        'grantType': 0,
        giftQuantity: null,
        giftPoint: null,
        'num': null,
        'countAmount': null,
        'rangeType': null,
        'overlayType': null,
        activityDegree: '',
        'activityDegreeName': null,
        days: '',
        'effectiveBeginDate': null,
        'effectiveEndDate': null,
        'registerBeginDate ': null,
        'registerEndDate': null,
        'useNum ': null,
        userlevel: ''
      },
      // 领取时间
      chose_dateRange_start: {},
      chose_dateRange_end: {},
      use_issueVal: '',
      tableData: [],
      receiveId: '', // 领用记录ID
      receiveTable: {
        sels: [],
        tableData: [],
        total: 0,
        currentPage: 1,
        pageSize: 10,
        sortProp: null,
        sortOrder: 'ascending',
        condition: {
          name: '',
          number: ''
        },
        listLoading: false
      },
      myFormVisible: false
    };
  },
  methods: {
    // 领用记录--查询
    searchReceive () {
      let filters = '';
      // 状态
      if (this.couponReceiveStatusValue !== '') {
        filters += 'EQ_status=' + this.couponReceiveStatusValue + ';';
      }
      // 日期
      if (this.ReceivePicker.length > 0 && this.ReceivePicker[0] != null && this.ReceivePicker[1] != null) {
        filters += 'GTE_createDate=' + this.ReceivePicker[0].toJSON() + ';';
        filters += 'LTE_createDate=' + this.ReceivePicker[1].toJSON() + ';';
      }
      getReceiveList({
        id: this.receiveId,
        page: this.receiveTable.currentPage - 1,
        size: this.receiveTable.pageSize,
        filters: filters + 'LIKE_coupon.id=' + this.receiveId + ';',
        sort: (this.receiveTable.sortProp === null ? '' : this.receiveTable.sortProp + (this.receiveTable.sortOrder === 'ascending' ? ',desc' : ',asc'))
      }).then((res) => {
        if (res.data) {
          this.receiveTable.tableData = res.data;
          this.receiveTable.total = Number(res.headers['x-total-count']);
          this.receiveTable.listLoading = false;
        }
      });
    },
    // 领用记录  重置
    receiveResert () {
      this.ReceivePicker = '';
      this.couponReceiveStatusValue = '';
    },
    // 面值 //折扣判断
    myChange () {
      if (this.myForm.type === 114001002) {
        this.myStatus = false;
      } else {
        this.myStatus = true;
      }
    },

    // 查询 --搜索栏
    searchCoupon () {
      let filters = '';
      // 名称
      if (this.coupon !== '') {
        filters += 'LIKE_name=' + this.coupon + ';';
      }
      // 类型
      if (this.conponTypeValue !== '') {
        filters += 'EQ_type=' + this.conponTypeValue + ';';
      }

      // 状态
      if (this.couponStatusValue !== '') {
        filters += 'EQ_status=' + this.couponStatusValue + ';';
      }
      getCoupons({
        page: this.currentPage - 1,
        size: this.pageSize,
        filters: filters,
        sorts: (this.sortProp === null ? '' : this.sortProp + (this.sortOrder === 'ascending' ? ',desc' : ',asc'))
      }).then((res) => {
        if (res.data) {
          this.tableData = res.data;
          this.total = Number(res.headers['x-total-count']);
          this.listLoading = false;
        }
      });
    },
    // 类型--搜索栏
    searchType () {
      searchDictEntitys('114001').then((res) => {
        if (res.data) {
          this.conponType = res.data;
        }
      });
    },

    // 状态--搜索栏
    searchStatus () {
      searchDictEntitys('114003').then((res) => {
        if (res.data) {
          this.couponStatus = res.data;
        }
      });
    },
    // 导出
    //    deriveList () {
    //    },
    // 搜索栏--重置
    resetCondition () {
      this.conponTypeValue = '';
      this.couponStatusValue = '';
      this.coupon = '';
    },
    // 跳转领用记录
    receive (index, row) {
      this.$router.push('/marketing/receive/', row.id);
    },
    // 弹出发布窗口
    publish (index, row) {
      this.$confirm('确认发布该记录吗?(发布后不可编辑)', '提示', {
        type: 'warning'
      }).then(() => {
        publishDiscount(row.id, 114003002).then((res) => {
          if (res.data) {
            this.searchCoupon();
            this.$message({
              message: '发布成功',
              type: 'success'
            });
          }
        });
      }).catch(() => {

      });
    },
    // 弹出结束窗口
    overlish (index, row) {
      this.$confirm('确认结束该记录吗?(结束后不展示)', '提示', {
        type: 'warning'
      }).then(() => {
        publishDiscount(row.id, 114003003).then((res) => {
          if (res.data) {
            this.searchCoupon();
            this.$message({
              message: '发布成功',
              type: 'success'
            });
          }
        });
      }).catch(() => {

      });
    },

    // 删除单条数据操作
    handleDel (index, row) {
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        batchCoupons(row.id).then((res) => {
          this.searchCoupon();
          this.$message({
            message: '删除成功',
            type: 'success'
          });
        });
      }).catch(() => {

      });
    },
    // 新增修改数据提交
    handleSubmit (status) {
      this.submitLoading = true;
      this.myForm.isIssue = 111002002;
      this.myForm.status = status;
      if (this.myForm.myCreateDate.length > 0 && this.myForm.myCreateDate[0] == null) {
        this.myForm.myCreateDate = [];
      }
      if (this.myForm.registerDate.length > 0 && this.myForm.registerDate[0] == null) {
        this.myForm.registerDate = [];
      }
      this.$refs['myForm'].validate((valid) => {
        if (valid) {
          if (this.myForm.useCondition !== 0) { // 不是减免，清空
            this.myForm.useConditionVal = '';
          }
          if (this.myForm.frequencyVal <= 0 && this.myForm.frequencyVal != null) {
            return this.$message.error('领取次数请输入大于0的正整数');
          }
          if (this.myForm.frequency === 1) { // 领取次数无限制时，清空限人数
            this.myForm.frequencyVal = '';
          }
          if (this.myForm.agingType === 1) {
            if (this.myForm.days <= 0 || this.myForm.days === '' || this.myForm.days == null || this.myForm.days === undefined) {
              return this.$message.error('请输入大于0的正整数');
            }
          }
          this.myForm.effectiveBeginDate = this.myForm.myCreateDate[0];
          this.myForm.effectiveEndDate = this.myForm.myCreateDate[1];
          this.myForm.registerBeginDate = this.myForm.registerDate[0];
          this.myForm.registerEndDate = this.myForm.registerDate[1];
          saveCoupons(this.myForm).then((res) => {
            this.submitLoading = false;
            if (res.data) {
              this.myFormVisible = false;
              this.searchCoupon();
            }
          }).catch(function (error) {
            console.log(error);
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 重置表单
    resetForm () {
      if (this.$refs.myForm) {
        this.$refs.myForm.resetFields();
      }
      this.$ue.resetObjNull(this.myForm);
    },
    // 弹出领用记录
    receiveRecord (index, row) {
      this.dialogTitle = '领用记录';
      this.myFormReceive = true;
      this.receiveTable.listLoading = true;
      let str = [];
      for (let p in this.receiveTable.condition) {
        if (this.receiveTable.condition[p] !== '' && this.receiveTable.condition[p] !== null) {
          str.push(p + '=' + this.receiveTable.condition[p]);
        }
      }
      this.receiveTable.listLoading = true;
      this.receiveId = row.id;
      getReceiveList({
        id: row.id,
        page: this.receiveTable.currentPage - 1,
        size: this.receiveTable.pageSize,
        filters: str.join(';') + 'LIKE_coupon.id=' + row.id + ';',
        sort: (this.receiveTable.sortProp === null ? '' : this.receiveTable.sortProp + (this.receiveTable.sortOrder === 'ascending' ? ',desc' : ',asc'))
      }).then((res) => {
        this.receiveTable.listLoading = false;
        if (res.data) {
          this.receiveTable.tableData = res.data;
          this.receiveTable.total = Number(res.headers['x-total-count']);
        }
      });
    },
    // 弹出查看详情
    detailsView (index, row) {
      this.isActive.hasFalse = true;
      this.dialogTitle = '查看详情';
      this.resetForm();
      this.myFormVisible = true;
      this.myForm = Object.assign({
        'name': null,
        'statusName': null,
        'myCreateDate': [],
        'registerDate': [],
        'remark': null,
        'type': null,
        'isIssue': null,
        'faceValue': null,
        'useCondition': 0,
        'useConditionVal': null,
        'frequency': null,
        'frequencyVal': '',
        'agingType': null,
        'grantType': null,
        'num': null,
        'countAmount': null,
        'rangeType': null,
        'overlayType': null,
        activityDegree: '',
        'activityDegreeName': null,
        days: '',
        'effectiveBeginDate': null,
        'effectiveEndDate': null,
        'registerBeginDate ': null,
        'registerEndDate': null,
        'useNum ': null,
        userlevel: ''
      }, row);
      if (row.effectiveBeginDate !== null && row.effectiveEndDate !== null) {
        this.myForm.myCreateDate = [row.effectiveBeginDate, row.effectiveEndDate];
      }
      if (row.registerBeginDate !== null && row.registerEndDate !== null) {
        this.myForm.registerDate = [row.registerBeginDate, row.registerEndDate];
      }
    },
    // 弹出编辑窗体
    handleAddEit (index, row) {
      this.submitLoading = false;
      this.isActive.hasFalse = false;
      this.dialogTitle = '编辑';
      this.resetForm();
      this.myFormVisible = true;
      this.myForm = Object.assign({
        'name': null,
        'statusName': null,
        'myCreateDate': [],
        'registerDate': [],
        'remark': null,
        'type': null,
        'isIssue': null,
        'faceValue': null,
        'useCondition': 0,
        'useConditionVal': null,
        'frequency': null,
        'frequencyVal': '',
        'agingType': null,
        'grantType': null,
        'num': null,
        'countAmount': null,
        'rangeType': null,
        'overlayType': null,
        activityDegree: '',
        'activityDegreeName': null,
        days: '',
        'effectiveBeginDate': null,
        'effectiveEndDate': null,
        'registerBeginDate ': null,
        'registerEndDate': null,
        'useNum ': null,
        userlevel: ''
      }, row);
      if (row.effectiveBeginDate !== null && row.effectiveEndDate !== null) {
        this.myForm.myCreateDate = [row.effectiveBeginDate, row.effectiveEndDate];
      }
      if (row.registerBeginDate !== null && row.registerEndDate !== null) {
        this.myForm.registerDate = [row.registerBeginDate, row.registerEndDate];
      }
    },
    // 弹出添加窗体
    handleAdd () {
      this.isActive.hasFalse = false;
      this.myStatus = false;
      this.dialogTitle = '新增';
      this.resetForm();
      this.myFormVisible = true;
      this.submitLoading = false;
    },
    // 跳转到新增页面
    handleAdd1 () {
      //                this.$router.push('/order/table_add');
    },
    // 多选操作
    selsChange (sels) {
      this.sels = sels;
    },
    // 排序操作
    sortChange (o) {
      this.sortProp = o.prop;
      this.sortOrder = o.order;
      this.searchCoupon();
    },
    // 每页几条操作
    handleSizeChange (val) {
      this.pageSize = val;
      this.searchCoupon();
    },
    // 第几页操作
    handleCurrentChange (val) {
      this.currentPage = val;
      this.searchCoupon();
    },

    // 多选操作
    selsChange1 (sels) {
      this.receiveTable.sels = sels;
    },
    // 排序操作
    sortChange1 (o) {
      this.receiveTable.sortProp = o.prop;
      this.receiveTable.sortOrder = o.order;
      this.searchReceive();
    },
    // 每页几条操作
    handleSizeChange1 (val) {
      this.receiveTable.pageSize = val;
      this.searchReceive();
    },
    // 第几页操作
    handleCurrentChange1 (val) {
      this.receiveTable.currentPage = val;
      this.searchReceive();
    },
    // 获取表格数据
    getTableData () {
      let str = [];
      for (let p in this.condition) {
        if (this.condition[p] !== '' && this.condition[p] !== null) {
          str.push(p + '=' + this.condition[p]);
        }
      }
      this.listLoading = true;
      getCoupons({
        page: this.currentPage - 1,
        size: this.pageSize,
        filters: str.join(';'),
        sort: (this.sortProp === null ? '' : this.sortProp + (this.sortOrder === 'ascending' ? ',desc' : ',asc'))
      }).then((res) => {
        if (res.data) {
          this.tableData = res.data;
          this.total = Number(res.headers['x-total-count']);
          this.listLoading = false;
        }
      });
    }
  },

  // 初始化数据
  mounted () {
    this.$store.commit('initDict');
    this.searchType();
    this.searchStatus();
    this.getTableData();
  }
};
</script>

<style lang="less">
  .active {
    display: none
  }
</style>
